{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 可视化系统使用说明\n",
    "\n",
    "目前，初步完成了基于天河二号的可视化系统的使用说明 ，用户可以参考此说明文件进行体验，如有问题请和我们沟通。\n",
    "\n",
    "在使用环境前，你需要了解：\n",
    "\n",
    "* 需要使用前面的节点分区（ln0\\ln1\\ln3 等） ，目前暂不支持基金用户（ln7\\ln8）\n",
    "\n",
    "* 需要具有 docker 作业分区的权限 \n",
    "\n",
    "* 此工具可能会不定期进行更新。\n",
    "\n",
    "* 此工具使用过程中需要您配置好SSH 的免yes 登陆，也就是配置改为 ： CheckHostIP no ， 如有疑问去Issues 开贴询问或查询。\n",
    "\n",
    "* VNC 桌面一旦开启就会占用计算节点并进行计费，用户在不使用时请及时退出，避免浪费。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. Quick start \n",
    "\n",
    "如果是第一次使用，首先需要将脚本工具复制过去，并进入所在的文件夹里。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hostport  killallnonvc.sh  runvnc.sh  server.sh  settings.sh\r\n"
     ]
    }
   ],
   "source": [
    "cp -r /WORK/app/vis ~/vis \n",
    "cd ~/vis\n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "运行下面的命令即可完成VNC 环境的启动。（在此之前您最好修改配置）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456 654321 docker\r\n",
      "rm: cannot remove `log.httpadd': No such file or directory\r\n",
      "Submitted batch job 416772\r\n",
      "    http://172.16.23.16:6080/vnc.html?host=172.16.23.16&port=6080\r\n"
     ]
    }
   ],
   "source": [
    "source runvnc.sh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在，您就可以使用浏览器访问最后的网址来访问桌面环境了。\n",
    "\n",
    "![use-vnc](https://cloud.githubusercontent.com/assets/15058246/15538344/24ab81b4-22ae-11e6-9462-fbd990eeeeb6.jpg)\n",
    "\n",
    "\n",
    "## 1. 配置参数（修改密码）\n",
    "\n",
    "主要的参数是在 脚本文件 settings.sh 里面，按需求进行修改即可。别的用户如果获得或者猜测出您的密码也是可以通过这个网址访问您的计算环境的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#!/bin/sh\r\n",
      "export VNC_PW1=123456\r\n",
      "export VNC_PW2=654321\r\n",
      "export VNC_PAR=docker\r\n",
      "export VNC_SNIP=172.16.23.16\r\n",
      "export VNC_SNNM=ln6-gn0\r\n",
      "export VNC_SNNMS=ln6\r\n"
     ]
    }
   ],
   "source": [
    "cat settings.sh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其中，您需要修改的是`export VNC_PW1=123456` 和 `export VNC_PW2=654321` 两个。\n",
    "\n",
    "密码 123456 是VNC 验证的密码 ， 请重设。\n",
    "\n",
    "密码 654321 是 VNC 的观众密码 ， 也请重设。 用观众密码登陆的话，只能看，不能操作 。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 退出VNC 环境 \n",
    "VNC 环境有两部门组成：申请的计算节点 和 在登陆节点的转发代理，这两者目前都需要主动释放"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             JOBID PARTITION     NAME         USER ST       TIME  NODES NODELIST(REASON)\r\n",
      "            416772    docker server.s nscc-gz_jian  R      19:11      1 cn7557\r\n"
     ]
    }
   ],
   "source": [
    "yhqueue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如图所示，使用 yhq 可以看到占用的节点资源， 作业名为 server.sh (只显示了前8个字符)，可以用yhcancel 释放节点资源。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": []
    }
   ],
   "source": [
    "yhcancel 416772"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "然后可以用这里的工具释放登陆节点的转发代理 ，运行下面的命令即可：(如果您拷贝过来的位置不同，请自行修改) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "kill 36466: No such process\r\n"
     ]
    }
   ],
   "source": [
    "ssh ln6 ~/vis/killallnonvc.sh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里多出的一行提示信息不用管。现在整个系统资源就已经完整释放了。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
